package likou;

import java.util.Arrays;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/04/25 12:13
 */
public class _5739 {
    public int maxFrequency(int[] nums, int k) {
        Arrays.sort(nums);
        for (int i=0;i<nums.length-1;i++){
            nums[i]=nums[i+1]-nums[i];
        }
        int sum = 0;
        int left = 0;
        int right = 0;
        for (right=0;right<nums.length-1;right++){
            sum+=nums[right];
            if (sum>k){
                left++;
            }
        }
        return right-left+1;
    }
}
